package BinaryTreePackage2;

import org.junit.jupiter.api.Test;

import java.util.Stack;

/**
 * @author Lzm
 * @version 1.0
 */
public class StackAsQueue {

  Stack<Object> stack1 = new Stack<>();
  Stack<Object> stack2 = new Stack<>();
  public StackAsQueue(){}
  public void push(int number){
    stack1.push(number);
    while(!stack1.isEmpty()){
      stack2.push(stack1.pop());
    }
  }
  public Object pop(){
    if (!stack2.isEmpty()){
      return stack2.pop();
    }
    throw new RuntimeException("队列为空");
  }
  public Object peek(){
    while(!stack1.isEmpty()){
      stack2.push(stack1.pop());
    }
    if (!stack2.isEmpty()){
      return stack2.peek();
    }
    else{
      throw new RuntimeException("队列为空");
    }
  }
}
